package org.jeecg.modules.service.impl;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.constant.CommonCuckoo;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.dto.PlatformManagementDto;
import org.jeecg.modules.entity.CuPlatformManagement;
import org.jeecg.modules.mapper.CuPlatformManagementMapper;
import org.jeecg.modules.service.ICuPlatformManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 平台列表
 * @Author: jeecg-boot
 * @Date: 2024-07-12
 * @Version: V1.0
 */
@Service
public class CuPlatformManagementServiceImpl extends ServiceImpl<CuPlatformManagementMapper, CuPlatformManagement> implements ICuPlatformManagementService {

    private final String key = "platformList";

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private CuPlatformManagementMapper cuPlatformManagementMapper;

    @Override
    public List<PlatformManagementDto> PlatformlistAll() {
        List<PlatformManagementDto> list = (List<PlatformManagementDto>) redisUtil.get(key);
        if (ObjectUtil.isNotEmpty(list)) {
            return list;
        }
        list = cuPlatformManagementMapper.PlatformlistAll("1");
        if (ObjectUtil.isEmpty(list)) {
            return null;
        }
        redisUtil.set(key, list, CommonCuckoo.CACHE_TIME);
        return list;
    }

    @Override
    public boolean save(CuPlatformManagement cuPlatformManagement) {
        redisUtil.del(key);
        return super.save(cuPlatformManagement);
    }

    @Override
    public boolean updateById(CuPlatformManagement cuPlatformManagement) {
        redisUtil.del(key);
        return super.updateById(cuPlatformManagement);
    }

    @Override
    public boolean removeById(String id) {
        redisUtil.del(key);
        return super.removeById(id);
    }

    @Override
    public boolean removeByIds(List<String> ids) {
        redisUtil.del(key);
        return super.removeByIds(ids);
    }
}
